%
% Author: Vasyl Mykhalchuk
%
%========================================================================
% Create color info based on of deformation scalar field

function [colorInfo] = createColorInfo(criticalPoints, scalarField, h)
[nV, x] = size(scalarField);
colorInfo = zeros(nV, 3, 'uint8');
for i = 1:nV
    colorInfo(i,:) = [0 0 0];
end%for

if ( criticalPoints == 0 )
    return;
end%if

[nCP, x] = size(criticalPoints);

% Creating color info for entropy fields
if ( h )
    for i = 1:nCP
        color = uint8( 100 * abs(scalarField(criticalPoints(i))) );  
        colorInfo(criticalPoints(i),:)= [color color color];
    end%for
    return;
end%if

for i = 1:nCP
    color = uint8( 255 * abs(scalarField(criticalPoints(i))) );
    if color > 255
        color = 255;
    elseif ( (color < 50) && (color > 15) )
        color = 50;
    end
    
    %colorR=color;colorG=color;colorB=color;
    
    if ( scalarField(criticalPoints(i)) < 0 )
        colorR =0; colorG = color; colorB = color;
    elseif( scalarField(criticalPoints(i)) >= 0 )
        colorR = color; colorG = 0; colorB = 0;
    end%if
    
    colorInfo(criticalPoints(i),:)= [colorR colorG colorB];
end%for

end%function create color info
